package hashTable;

import java.util.HashMap;
import java.util.Map;

public class N454_FourSumII {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i : nums1)
            for (int j : nums2)
                map.put((i + j), map.getOrDefault((i + j), 0) + 1);
        int count = 0;
        for (int i : nums3)
            for (int j : nums4)
                if (map.containsKey(-(i + j))) {
                    count += map.get(-(i + j));
                }
        return count;
    }

    public static void main(String[] args) {
        N454_FourSumII solution = new N454_FourSumII();
//        输入：nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]
        int[]
                num1 = {0},
                num2 = {0},
                num3 = {0},
                num4 = {0};
        System.out.println(solution.fourSumCount(num1, num2, num3, num4));
    }
}
